package br.com.gerador.main;

import javax.swing.table.AbstractTableModel;

import br.com.gerador.icomponent.IGComponent;
import br.com.gerador.icomponent.IGProprierdade;

public class PropriedadeData extends AbstractTableModel {
	    private String[] columnNames = {"Propriedade","Valor"};
	    private String[][] data;
	    private IGProprierdade component;
	    
	    public PropriedadeData(String[][] data,IGProprierdade component) {
			this.data = data;
			this.component = component;
		}

	    public int getColumnCount() {
	        return columnNames.length;
	    }

	    public int getRowCount() {
	        return data.length;
	    }

	    public String getColumnName(int col) {
	        return columnNames[col];
	    }
	    
	    public Object getValueAt(int row, int col) {
	        return data[row][col];
	    }

	    public Class getColumnClass(int c) {
	        return getValueAt(0, c).getClass();
	    }

	    public boolean isCellEditable(int row, int col) {
	        if (col == 0) {
	            return false;
	        } else {
	            return true;
	        }
	    }

	    public void setValueAt(Object value, int row, int col) {
	        data[row][col] = (String)value;
	        String method = data[row][2];
        	component.firePropriedade(method, value);
	        fireTableCellUpdated(row, col);
	    }
}
